package oop.ex2.tokenizer;

import oop.ex2.expression.ExpressionNode;
import oop.ex2.expression.NegOpNode;

/**
 * This checks for an negation unary operation: '-'.
 * @author daniel_i_l
 *
 */
public class NegOpAnalyzer extends TokenAnalyzer {
	private static final String PATTERN = "-[0-9A-Z@\\[]";

	/**
	 * Initialize the search pattern.
	 */
	public NegOpAnalyzer() {
		super(PATTERN);
	}

    @Override
    public int getEndOfPatternPosition(String line)
	{
        //we match the negation for more than one char to make sure that
        //after the negation there're no spaces. But we only want to match the - sign.
		return Math.max(super.getEndOfPatternPosition(line) -1, -1);

	}

	@Override
	public ExpressionNode getExpressionNode() {
		return new NegOpNode(_matchedString);
	}

}
